#pragma once;

#include <windows.h>
#include <boost/function.hpp>

#include "AutoLock.h"


//wm_timer
//win message queue require!

namespace yet {


/*
 int n = 5;
 void onTimer(WinLoop* loop, Timer* t){
 cout<<"Timer"<<endl;
 if(!n--){
 t->stop();
 loop->quit(0);
 }
 }

 static void test() {
 WinLoop loop;
 Timer t;
 t.OnTimer = boost::bind(onTimer, &loop, _1);
 t.start(1000);
 loop.loop();
 }
 */

class Timer {
public:
	Timer();
	virtual ~Timer();
	bool start(UINT milliSeconds);
	void stop();
	bool isActive();
public:
	boost::function<void(Timer* timer)> OnTimer;
private:
	UINT timerID;
	ThreadLock idLock;

	friend void CALLBACK MyTimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
};

}

